package com.advich.ai.config;

import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.client.advisor.SimpleLoggerAdvisor;
import org.springframework.ai.ollama.OllamaChatModel;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.ai.vectorstore.VectorStore;
import org.springframework.ai.vectorstore.memory.InMemoryVectorStore;
import jakarta.annotation.PostConstruct;
import org.springframework.ai.document.Document;
import java.util.List;

/**
 * @author Zenas
 */
@Configuration
public class CommonConfiguration {
    private final VectorStore vectorStore;
    public CommonConfiguration(VectorStore vectorStore) {
        this.vectorStore = vectorStore;
    }
    @PostConstruct
    public void loadDocs() {
        vectorStore.add(List.of(
            new Document("Spring AI 是一个用于集成 AI 能力的 Spring 项目。"),
            new Document("RAG 是一种结合检索和生成的 AI 技术。"),
            new Document("OpenAI 提供了强大的大语言模型 API。")
        ));
    }

    @Bean
    public ChatClient chatClient(OllamaChatModel model) {
        return ChatClient.builder(model)
                .defaultSystem("你是可爱的助手，名字叫小团团")
                .defaultAdvisors(new SimpleLoggerAdvisor())
                .build();
    }

    @Bean
    public VectorStore vectorStore() {
        return new InMemoryVectorStore();
    }

}
